package com.wm.task.server;

import com.wm.task.common.util.Const;
import com.wm.task.server.handler.SocketHandler;

import java.net.ServerSocket;
import java.net.Socket;

public class Server {
    private int port = Const.SERVER_PORT;
    public Server(){}
    public Server(int port){
        this.port = port;
    }
    public void start(){
        try(ServerSocket serverSocket = new ServerSocket(port)){
            while(true){
                System.out.println("正在监听"+port+"端口...");
                Socket socket = serverSocket.accept();
                try{
                    SocketHandler socketHandler = new SocketHandler(socket);
                    if(socketHandler != null){
                        socketHandler.startProcess();
                    }
                } catch (Exception e) {
                }

            }
        } catch (Exception e) {
            System.out.println("服务器异常！！！");
        }
    }
}
